<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 
      Vue3 使用的是 Proxy 来实现数据的劫持做到响应式。
      如下的四个操作都可以生效。
     -->
    <div id="app">
      <button @click="fn1">修改 list[1] 为 西瓜</button>
      <button @click="fn2">修改 list.length = 1</button>
      <button @click="fn3">给 person 新增一个 sex</button>
      <button @click="fn4">删除 person 的 age 属性</button>
      <ul>
        <li v-for="(item, index) in list" :key="index">{{ item }}</li>
      </ul>
      <hr />
      <ul>
        <li v-for="(value, key, index) in person" :key="index">
          {{ value }} - {{ key }}
        </li>
      </ul>
    </div>

    <script src="../lib/vue-3.js"></script>

    <script>
      Vue.createApp({
        data() {
          return {
            list: ["Apple", "Banana", "Orange"],
            person: {
              name: "张三",
              age: 18,
            },
          };
        },
        methods: {
          fn1() {
            this.list[1] = "西瓜";
            console.log("this.list", this.list);
          },
          fn2() {
            this.list.length = 1;
          },
          fn3() {
            this.person.sex = "男";
          },
          fn4() {
            delete this.person.age;
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
